2023-07-27 00:31:52 -05:00
|
|
|
<!--
|
2024-02-13 09:59:27 -06:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 00:31:52 -05:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2022-06-23 10:47:55 -05:00
|
|
|
<template>
|
|
|
|
<MkStickyContainer>
|
2022-06-20 03:38:49 -05:00
|
|
|
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
2023-05-19 02:20:53 -05:00
|
|
|
<MkSpacer :contentMax="800" :marginMin="16" :marginMax="32">
|
2023-01-05 22:40:17 -06:00
|
|
|
<div class="cwepdizn _gaps_m">
|
2023-05-19 02:20:53 -05:00
|
|
|
<MkFolder :defaultOpen="true">
|
2022-06-23 10:47:55 -05:00
|
|
|
<template #label>{{ i18n.ts.backgroundColor }}</template>
|
|
|
|
<div class="cwepdizn-colors">
|
|
|
|
<div class="row">
|
|
|
|
<button v-for="color in bgColors.filter(x => x.kind === 'light')" :key="color.color" class="color _button" :class="{ active: theme.props.bg === color.color }" @click="setBgColor(color)">
|
|
|
|
<div class="preview" :style="{ background: color.forPreview }"></div>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="row">
|
|
|
|
<button v-for="color in bgColors.filter(x => x.kind === 'dark')" :key="color.color" class="color _button" :class="{ active: theme.props.bg === color.color }" @click="setBgColor(color)">
|
|
|
|
<div class="preview" :style="{ background: color.forPreview }"></div>
|
|
|
|
</button>
|
|
|
|
</div>
|
2022-01-04 07:42:04 -06:00
|
|
|
</div>
|
2023-01-08 18:41:25 -06:00
|
|
|
</MkFolder>
|
2022-06-23 10:47:55 -05:00
|
|
|
|
2023-05-19 02:20:53 -05:00
|
|
|
<MkFolder :defaultOpen="true">
|
2022-06-23 10:47:55 -05:00
|
|
|
<template #label>{{ i18n.ts.accentColor }}</template>
|
|
|
|
<div class="cwepdizn-colors">
|
|
|
|
<div class="row">
|
|
|
|
<button v-for="color in accentColors" :key="color" class="color rounded _button" :class="{ active: theme.props.accent === color }" @click="setAccentColor(color)">
|
|
|
|
<div class="preview" :style="{ background: color }"></div>
|
|
|
|
</button>
|
|
|
|
</div>
|
2022-01-04 07:42:04 -06:00
|
|
|
</div>
|
2023-01-08 18:41:25 -06:00
|
|
|
</MkFolder>
|
2022-06-23 10:47:55 -05:00
|
|
|
|
2023-05-19 02:20:53 -05:00
|
|
|
<MkFolder :defaultOpen="true">
|
2022-06-23 10:47:55 -05:00
|
|
|
<template #label>{{ i18n.ts.textColor }}</template>
|
|
|
|
<div class="cwepdizn-colors">
|
|
|
|
<div class="row">
|
|
|
|
<button v-for="color in fgColors" :key="color" class="color char _button" :class="{ active: (theme.props.fg === color.forLight) || (theme.props.fg === color.forDark) }" @click="setFgColor(color)">
|
|
|
|
<div class="preview" :style="{ color: color.forPreview ? color.forPreview : theme.base === 'light' ? '#5f5f5f' : '#dadada' }">A</div>
|
|
|
|
</button>
|
|
|
|
</div>
|
2022-01-04 07:42:04 -06:00
|
|
|
</div>
|
2023-01-08 18:41:25 -06:00
|
|
|
</MkFolder>
|
2022-06-23 10:47:55 -05:00
|
|
|
|
2023-05-19 02:20:53 -05:00
|
|
|
<MkFolder :defaultOpen="false">
|
2022-12-19 04:01:30 -06:00
|
|
|
<template #icon><i class="ti ti-code"></i></template>
|
2022-06-23 10:47:55 -05:00
|
|
|
<template #label>{{ i18n.ts.editCode }}</template>
|
|
|
|
|
2023-01-05 22:40:17 -06:00
|
|
|
<div class="_gaps_m">
|
2023-12-15 22:18:12 -06:00
|
|
|
<MkCodeEditor v-model="themeCode" lang="json5">
|
2022-06-23 10:47:55 -05:00
|
|
|
<template #label>{{ i18n.ts._theme.code }}</template>
|
2023-12-15 22:18:12 -06:00
|
|
|
</MkCodeEditor>
|
2023-01-05 18:41:14 -06:00
|
|
|
<MkButton primary @click="applyThemeCode">{{ i18n.ts.apply }}</MkButton>
|
2022-06-23 10:47:55 -05:00
|
|
|
</div>
|
2023-01-08 18:41:25 -06:00
|
|
|
</MkFolder>
|
2022-06-23 10:47:55 -05:00
|
|
|
|
2023-05-19 02:20:53 -05:00
|
|
|
<MkFolder :defaultOpen="false">
|
2022-06-23 10:47:55 -05:00
|
|
|
<template #label>{{ i18n.ts.addDescription }}</template>
|
|
|
|
|
2023-01-05 22:40:17 -06:00
|
|
|
<div class="_gaps_m">
|
2023-01-07 00:09:46 -06:00
|
|
|
<MkTextarea v-model="description">
|
2022-06-23 10:47:55 -05:00
|
|
|
<template #label>{{ i18n.ts._theme.description }}</template>
|
2023-01-07 00:09:46 -06:00
|
|
|
</MkTextarea>
|
2022-01-04 07:42:04 -06:00
|
|
|
</div>
|
2023-01-08 18:41:25 -06:00
|
|
|
</MkFolder>
|
2022-06-23 10:47:55 -05:00
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2020-07-10 22:12:35 -05:00
|
|
|
</template>
|
|
|
|
|
2022-01-16 00:02:15 -06:00
|
|
|
<script lang="ts" setup>
|
2023-12-06 23:42:09 -06:00
|
|
|
import { watch, ref, computed } from 'vue';
|
2021-04-03 23:00:39 -05:00
|
|
|
import { toUnicode } from 'punycode/';
|
2022-05-01 08:51:07 -05:00
|
|
|
import tinycolor from 'tinycolor2';
|
2022-06-10 00:36:55 -05:00
|
|
|
import { v4 as uuid } from 'uuid';
|
2022-05-01 08:51:07 -05:00
|
|
|
import JSON5 from 'json5';
|
2020-07-10 22:12:35 -05:00
|
|
|
|
2023-01-05 18:41:14 -06:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-12-15 22:18:12 -06:00
|
|
|
import MkCodeEditor from '@/components/MkCodeEditor.vue';
|
2023-01-07 00:09:46 -06:00
|
|
|
import MkTextarea from '@/components/MkTextarea.vue';
|
2023-01-08 18:41:25 -06:00
|
|
|
import MkFolder from '@/components/MkFolder.vue';
|
2020-07-10 22:12:35 -05:00
|
|
|
|
2023-09-19 02:37:43 -05:00
|
|
|
import { $i } from '@/account.js';
|
|
|
|
import { Theme, applyTheme } from '@/scripts/theme.js';
|
2022-05-28 07:59:23 -05:00
|
|
|
import lightTheme from '@/themes/_light.json5';
|
|
|
|
import darkTheme from '@/themes/_dark.json5';
|
2023-09-19 02:37:43 -05:00
|
|
|
import { host } from '@/config.js';
|
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { ColdDeviceStorage, defaultStore } from '@/store.js';
|
2023-12-24 01:16:58 -06:00
|
|
|
import { addTheme } from '@/theme-store.js';
|
2023-09-19 02:37:43 -05:00
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { useLeaveGuard } from '@/scripts/use-leave-guard.js';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata.js';
|
2022-01-16 00:02:15 -06:00
|
|
|
|
|
|
|
const 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' },
|
|
|
|
{ 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' },
|
|
|
|
{ color: '#362e29', kind: 'dark', forPreview: '#735c4d' },
|
|
|
|
{ color: '#303629', kind: 'dark', forPreview: '#506d2f' },
|
|
|
|
{ color: '#293436', kind: 'dark', forPreview: '#258192' },
|
|
|
|
{ color: '#2e2936', kind: 'dark', forPreview: '#504069' },
|
|
|
|
{ color: '#252722', kind: 'dark', forPreview: '#3c462f' },
|
|
|
|
{ color: '#212525', kind: 'dark', forPreview: '#303e3e' },
|
|
|
|
{ color: '#191919', kind: 'dark', forPreview: '#272727' },
|
|
|
|
] as const;
|
|
|
|
const accentColors = ['#e36749', '#f29924', '#98c934', '#34c9a9', '#34a1c9', '#606df7', '#8d34c9', '#e84d83'];
|
|
|
|
const 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' },
|
|
|
|
{ color: 'blue', forLight: '#676880', forDark: '#d1d2e4', forPreview: '#7275d8' },
|
|
|
|
{ color: 'pink', forLight: '#84667d', forDark: '#e4d1e0', forPreview: '#b12390' },
|
|
|
|
];
|
|
|
|
|
2023-12-06 23:42:09 -06:00
|
|
|
const theme = ref<Partial<Theme>>({
|
2022-01-16 00:02:15 -06:00
|
|
|
base: 'light',
|
|
|
|
props: lightTheme.props,
|
|
|
|
});
|
2023-12-06 23:42:09 -06:00
|
|
|
const description = ref<string | null>(null);
|
|
|
|
const themeCode = ref<string | null>(null);
|
|
|
|
const changed = ref(false);
|
2020-07-10 22:12:35 -05:00
|
|
|
|
2023-12-06 23:42:09 -06:00
|
|
|
useLeaveGuard(changed);
|
2020-07-10 22:12:35 -05:00
|
|
|
|
2022-01-16 00:02:15 -06:00
|
|
|
function showPreview() {
|
2022-05-29 05:21:36 -05:00
|
|
|
os.pageWindow('/preview');
|
2022-01-16 00:02:15 -06:00
|
|
|
}
|
2021-11-19 04:36:12 -06:00
|
|
|
|
2022-01-16 00:02:15 -06:00
|
|
|
function setBgColor(color: typeof bgColors[number]) {
|
2023-12-06 23:42:09 -06:00
|
|
|
if (theme.value.base !== color.kind) {
|
2022-01-16 00:02:15 -06:00
|
|
|
const base = color.kind === 'dark' ? darkTheme : lightTheme;
|
|
|
|
for (const prop of Object.keys(base.props)) {
|
|
|
|
if (prop === 'accent') continue;
|
|
|
|
if (prop === 'fg') continue;
|
2023-12-06 23:42:09 -06:00
|
|
|
theme.value.props[prop] = base.props[prop];
|
2020-07-10 22:12:35 -05:00
|
|
|
}
|
2022-01-16 00:02:15 -06:00
|
|
|
}
|
2023-12-06 23:42:09 -06:00
|
|
|
theme.value.base = color.kind;
|
|
|
|
theme.value.props.bg = color.color;
|
2020-07-10 22:12:35 -05:00
|
|
|
|
2023-12-06 23:42:09 -06:00
|
|
|
if (theme.value.props.fg) {
|
|
|
|
const matchedFgColor = fgColors.find(x => [tinycolor(x.forLight).toRgbString(), tinycolor(x.forDark).toRgbString()].includes(tinycolor(theme.value.props.fg).toRgbString()));
|
2022-01-16 00:02:15 -06:00
|
|
|
if (matchedFgColor) setFgColor(matchedFgColor);
|
|
|
|
}
|
|
|
|
}
|
2021-01-15 22:47:07 -06:00
|
|
|
|
2022-01-16 00:02:15 -06:00
|
|
|
function setAccentColor(color) {
|
2023-12-06 23:42:09 -06:00
|
|
|
theme.value.props.accent = color;
|
2022-01-16 00:02:15 -06:00
|
|
|
}
|
2021-01-15 22:47:07 -06:00
|
|
|
|
2022-01-16 00:02:15 -06:00
|
|
|
function setFgColor(color) {
|
2023-12-06 23:42:09 -06:00
|
|
|
theme.value.props.fg = theme.value.base === 'light' ? color.forLight : color.forDark;
|
2022-01-16 00:02:15 -06:00
|
|
|
}
|
2021-02-06 03:06:54 -06:00
|
|
|
|
2022-01-16 00:02:15 -06:00
|
|
|
function apply() {
|
2023-12-06 23:42:09 -06:00
|
|
|
themeCode.value = JSON5.stringify(theme.value, null, '\t');
|
|
|
|
applyTheme(theme.value, false);
|
|
|
|
changed.value = true;
|
2022-01-16 00:02:15 -06:00
|
|
|
}
|
2021-02-06 03:06:54 -06:00
|
|
|
|
2022-01-16 00:02:15 -06:00
|
|
|
function applyThemeCode() {
|
|
|
|
let parsed;
|
|
|
|
|
|
|
|
try {
|
2023-12-06 23:42:09 -06:00
|
|
|
parsed = JSON5.parse(themeCode.value);
|
2022-01-16 00:02:15 -06:00
|
|
|
} catch (err) {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-01-27 20:39:49 -06:00
|
|
|
text: i18n.ts._theme.invalid,
|
2022-01-16 00:02:15 -06:00
|
|
|
});
|
|
|
|
return;
|
2020-07-10 22:12:35 -05:00
|
|
|
}
|
2022-01-16 00:02:15 -06:00
|
|
|
|
2023-12-06 23:42:09 -06:00
|
|
|
theme.value = parsed;
|
2022-01-16 00:02:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
async function saveAs() {
|
|
|
|
const { canceled, result: name } = await os.inputText({
|
2022-01-27 20:39:49 -06:00
|
|
|
title: i18n.ts.name,
|
2024-01-30 04:53:53 -06:00
|
|
|
minLength: 1,
|
2022-01-16 00:02:15 -06:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2023-12-06 23:42:09 -06:00
|
|
|
theme.value.id = uuid();
|
|
|
|
theme.value.name = name;
|
|
|
|
theme.value.author = `@${$i.username}@${toUnicode(host)}`;
|
|
|
|
if (description.value) theme.value.desc = description.value;
|
|
|
|
await addTheme(theme.value);
|
|
|
|
applyTheme(theme.value);
|
2022-01-16 00:02:15 -06:00
|
|
|
if (defaultStore.state.darkMode) {
|
2023-12-06 23:42:09 -06:00
|
|
|
ColdDeviceStorage.set('darkTheme', theme.value);
|
2022-01-16 00:02:15 -06:00
|
|
|
} else {
|
2023-12-06 23:42:09 -06:00
|
|
|
ColdDeviceStorage.set('lightTheme', theme.value);
|
2022-01-16 00:02:15 -06:00
|
|
|
}
|
2023-12-06 23:42:09 -06:00
|
|
|
changed.value = false;
|
2022-01-16 00:02:15 -06:00
|
|
|
os.alert({
|
|
|
|
type: 'success',
|
2024-01-19 17:11:59 -06:00
|
|
|
text: i18n.tsx._theme.installed({ name: theme.value.name }),
|
2022-01-16 00:02:15 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-12-06 23:42:09 -06:00
|
|
|
watch(theme, apply, { deep: true });
|
2022-01-16 00:02:15 -06:00
|
|
|
|
2023-12-06 23:42:09 -06:00
|
|
|
const headerActions = computed(() => [{
|
2022-06-23 10:47:55 -05:00
|
|
|
asFullButton: true,
|
2022-12-19 04:01:30 -06:00
|
|
|
icon: 'ti ti-eye',
|
2022-06-23 10:47:55 -05:00
|
|
|
text: i18n.ts.preview,
|
|
|
|
handler: showPreview,
|
|
|
|
}, {
|
|
|
|
asFullButton: true,
|
2022-12-19 04:01:30 -06:00
|
|
|
icon: 'ti ti-check',
|
2022-06-23 10:47:55 -05:00
|
|
|
text: i18n.ts.saveAs,
|
|
|
|
handler: saveAs,
|
|
|
|
}]);
|
2022-06-20 03:38:49 -05:00
|
|
|
|
2023-12-06 23:42:09 -06:00
|
|
|
const headerTabs = computed(() => []);
|
2022-06-20 03:38:49 -05:00
|
|
|
|
2024-02-16 01:17:09 -06:00
|
|
|
definePageMetadata(() => ({
|
2022-06-20 03:38:49 -05:00
|
|
|
title: i18n.ts.themeEditor,
|
2022-12-19 04:01:30 -06:00
|
|
|
icon: 'ti ti-palette',
|
2024-02-16 01:17:09 -06:00
|
|
|
}));
|
2020-07-10 22:12:35 -05:00
|
|
|
</script>
|
|
|
|
|
2022-12-27 03:29:39 -06:00
|
|
|
<style lang="scss" scoped>
|
2021-01-09 02:18:45 -06:00
|
|
|
.cwepdizn {
|
2022-01-04 07:42:04 -06:00
|
|
|
::v-deep(.cwepdizn-colors) {
|
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
> .row {
|
|
|
|
> .color {
|
|
|
|
display: inline-block;
|
|
|
|
position: relative;
|
|
|
|
width: 64px;
|
|
|
|
height: 64px;
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
|
|
> .preview {
|
|
|
|
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;
|
|
|
|
}
|
2021-01-09 02:18:45 -06:00
|
|
|
|
2022-01-04 07:42:04 -06:00
|
|
|
&:hover {
|
2021-01-09 02:18:45 -06:00
|
|
|
> .preview {
|
2022-01-04 07:42:04 -06:00
|
|
|
transform: scale(1.1);
|
2020-07-10 22:12:35 -05:00
|
|
|
}
|
2022-01-04 07:42:04 -06:00
|
|
|
}
|
2020-07-10 22:12:35 -05:00
|
|
|
|
2022-01-04 07:42:04 -06:00
|
|
|
&.active {
|
|
|
|
box-shadow: 0 0 0 2px var(--divider) inset;
|
|
|
|
}
|
2020-07-10 22:12:35 -05:00
|
|
|
|
2022-01-04 07:42:04 -06:00
|
|
|
&.rounded {
|
|
|
|
border-radius: 999px;
|
2020-07-10 22:12:35 -05:00
|
|
|
|
2022-01-04 07:42:04 -06:00
|
|
|
> .preview {
|
2021-01-09 02:18:45 -06:00
|
|
|
border-radius: 999px;
|
2020-07-10 22:12:35 -05:00
|
|
|
}
|
2022-01-04 07:42:04 -06:00
|
|
|
}
|
2021-01-09 02:18:45 -06:00
|
|
|
|
2022-01-04 07:42:04 -06:00
|
|
|
&.char {
|
|
|
|
line-height: 42px;
|
2021-01-09 02:18:45 -06:00
|
|
|
}
|
2020-07-10 22:12:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|