egirlskey/packages/frontend/src/pages/theme-editor.vue

281 lines
8.6 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->
2022-06-23 15:47:55 +00:00
<template>
<MkStickyContainer>
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
2023-05-19 07:20:53 +00:00
<MkSpacer :contentMax="800" :marginMin="16" :marginMax="32">
2023-01-06 04:40:17 +00:00
<div class="cwepdizn _gaps_m">
2023-05-19 07:20:53 +00:00
<MkFolder :defaultOpen="true">
2022-06-23 15:47:55 +00: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 13:42:04 +00:00
</div>
2023-01-09 00:41:25 +00:00
</MkFolder>
2022-06-23 15:47:55 +00:00
2023-05-19 07:20:53 +00:00
<MkFolder :defaultOpen="true">
2022-06-23 15:47:55 +00: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 13:42:04 +00:00
</div>
2023-01-09 00:41:25 +00:00
</MkFolder>
2022-06-23 15:47:55 +00:00
2023-05-19 07:20:53 +00:00
<MkFolder :defaultOpen="true">
2022-06-23 15:47:55 +00: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 13:42:04 +00:00
</div>
2023-01-09 00:41:25 +00:00
</MkFolder>
2022-06-23 15:47:55 +00:00
2023-05-19 07:20:53 +00:00
<MkFolder :defaultOpen="false">
<template #icon><i class="ph-code ph-bold ph-lg"></i></template>
2022-06-23 15:47:55 +00:00
<template #label>{{ i18n.ts.editCode }}</template>
2023-01-06 04:40:17 +00:00
<div class="_gaps_m">
<MkCodeEditor v-model="themeCode" lang="json5">
2022-06-23 15:47:55 +00:00
<template #label>{{ i18n.ts._theme.code }}</template>
</MkCodeEditor>
2023-01-06 00:41:14 +00:00
<MkButton primary @click="applyThemeCode">{{ i18n.ts.apply }}</MkButton>
2022-06-23 15:47:55 +00:00
</div>
2023-01-09 00:41:25 +00:00
</MkFolder>
2022-06-23 15:47:55 +00:00
2023-05-19 07:20:53 +00:00
<MkFolder :defaultOpen="false">
2022-06-23 15:47:55 +00:00
<template #label>{{ i18n.ts.addDescription }}</template>
2023-01-06 04:40:17 +00:00
<div class="_gaps_m">
2023-01-07 06:09:46 +00:00
<MkTextarea v-model="description">
2022-06-23 15:47:55 +00:00
<template #label>{{ i18n.ts._theme.description }}</template>
2023-01-07 06:09:46 +00:00
</MkTextarea>
2022-01-04 13:42:04 +00:00
</div>
2023-01-09 00:41:25 +00:00
</MkFolder>
2022-06-23 15:47:55 +00:00
</div>
</MkSpacer>
</MkStickyContainer>
</template>
<script lang="ts" setup>
import { watch, ref, computed } from 'vue';
import { toUnicode } from 'punycode/';
refactor: use Vite to build instead of webpack (#8575) * update stream.ts * https://github.com/misskey-dev/misskey/pull/7769#issuecomment-917542339 * fix lint * clean up? * add app * fix * nanka iroiro * wip * wip * fix lint * fix loginId * fix * refactor * refactor * remove follow action * clean up * Revert "remove follow action" This reverts commit defbb416480905af2150d1c92f10d8e1d1288c0a. * Revert "clean up" This reverts commit f94919cb9cff41e274044fc69c56ad36a33974f2. * remove fetch specification * renoteの条件追加 * apiFetch => cli * bypass fetch? * fix * refactor: use path alias * temp: add submodule * remove submodule * enhane: unison-reloadに指定したパスに移動できるように * null * null * feat: ログインするアカウントのIDをクエリ文字列で指定する機能 * null * await? * rename * rename * Update read.ts * merge * get-note-summary * fix * swパッケージに * add missing packages * fix getNoteSummary * add webpack-cli * :v: * remove plugins * sw-inject分離したがテストしてない * fix notification.vue * remove a blank line * disconnect intersection observer * disconnect2 * fix notification.vue * remove a blank line * disconnect intersection observer * disconnect2 * fix * :v: * clean up config * typesを戻した * Update packages/client/src/components/notification.vue Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com> * disconnect * oops * Failed to load the script unexpectedly回避 sw.jsとlib.tsを分離してみた * truncate notification * Update packages/client/src/ui/_common_/common.vue Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * clean up * clean up * キャッシュ対策 * Truncate push notification message * クライアントがあったらストリームに接続しているということなので通知しない判定の位置を修正 * components/drive-file-thumbnail.vue * components/drive-select-dialog.vue * components/drive-window.vue * merge * fix * Service Workerのビルドにesbuildを使うようにする * return createEmptyNotification() * fix * i18n.ts * update * :v: * remove ts-loader * fix * fix * enhance: Service Workerを常に登録するように * pollEnded * URLをsw.jsに戻す * clean up * wip * wip * wip * wip * wip * wip * :v: * use import * fix * install rollup * use defineAsyncComponent. * fix emojilist * wip use defineAsyncComponent * popup(import -> popup(defineAsyncComponent(() => import * draggable? * fix init import * clean up * fix router * add comment * :v: * :v: * :v: * remove webpack * update vite * fix boot sequence * Revert "fix boot sequence" This reverts commit e893dbf37aed83bf9f12e427d98c78a7065b4a39. * revert boot import * never make two app div * ; * remove console.log * change clientEntry sequence * fix * Revert "fix" This reverts commit 12741b3d89950a31dbb1bb81477ddb27b0e9951a. * fix * add comment https://github.com/misskey-dev/misskey/pull/8575#issuecomment-1114239210 * add log * add comment Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com> Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-05-01 13:51:07 +00:00
import tinycolor from 'tinycolor2';
import { v4 as uuid } from 'uuid';
refactor: use Vite to build instead of webpack (#8575) * update stream.ts * https://github.com/misskey-dev/misskey/pull/7769#issuecomment-917542339 * fix lint * clean up? * add app * fix * nanka iroiro * wip * wip * fix lint * fix loginId * fix * refactor * refactor * remove follow action * clean up * Revert "remove follow action" This reverts commit defbb416480905af2150d1c92f10d8e1d1288c0a. * Revert "clean up" This reverts commit f94919cb9cff41e274044fc69c56ad36a33974f2. * remove fetch specification * renoteの条件追加 * apiFetch => cli * bypass fetch? * fix * refactor: use path alias * temp: add submodule * remove submodule * enhane: unison-reloadに指定したパスに移動できるように * null * null * feat: ログインするアカウントのIDをクエリ文字列で指定する機能 * null * await? * rename * rename * Update read.ts * merge * get-note-summary * fix * swパッケージに * add missing packages * fix getNoteSummary * add webpack-cli * :v: * remove plugins * sw-inject分離したがテストしてない * fix notification.vue * remove a blank line * disconnect intersection observer * disconnect2 * fix notification.vue * remove a blank line * disconnect intersection observer * disconnect2 * fix * :v: * clean up config * typesを戻した * Update packages/client/src/components/notification.vue Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com> * disconnect * oops * Failed to load the script unexpectedly回避 sw.jsとlib.tsを分離してみた * truncate notification * Update packages/client/src/ui/_common_/common.vue Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * clean up * clean up * キャッシュ対策 * Truncate push notification message * クライアントがあったらストリームに接続しているということなので通知しない判定の位置を修正 * components/drive-file-thumbnail.vue * components/drive-select-dialog.vue * components/drive-window.vue * merge * fix * Service Workerのビルドにesbuildを使うようにする * return createEmptyNotification() * fix * i18n.ts * update * :v: * remove ts-loader * fix * fix * enhance: Service Workerを常に登録するように * pollEnded * URLをsw.jsに戻す * clean up * wip * wip * wip * wip * wip * wip * :v: * use import * fix * install rollup * use defineAsyncComponent. * fix emojilist * wip use defineAsyncComponent * popup(import -> popup(defineAsyncComponent(() => import * draggable? * fix init import * clean up * fix router * add comment * :v: * :v: * :v: * remove webpack * update vite * fix boot sequence * Revert "fix boot sequence" This reverts commit e893dbf37aed83bf9f12e427d98c78a7065b4a39. * revert boot import * never make two app div * ; * remove console.log * change clientEntry sequence * fix * Revert "fix" This reverts commit 12741b3d89950a31dbb1bb81477ddb27b0e9951a. * fix * add comment https://github.com/misskey-dev/misskey/pull/8575#issuecomment-1114239210 * add log * add comment Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com> Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2022-05-01 13:51:07 +00:00
import JSON5 from 'json5';
2023-01-06 00:41:14 +00:00
import MkButton from '@/components/MkButton.vue';
import MkCodeEditor from '@/components/MkCodeEditor.vue';
2023-01-07 06:09:46 +00:00
import MkTextarea from '@/components/MkTextarea.vue';
2023-01-09 00:41:25 +00:00
import MkFolder from '@/components/MkFolder.vue';
2023-09-19 07:37:43 +00:00
import { $i } from '@/account.js';
import { Theme, applyTheme } from '@/scripts/theme.js';
2022-05-28 12:59:23 +00:00
import lightTheme from '@/themes/_light.json5';
import darkTheme from '@/themes/_dark.json5';
2023-09-19 07:37:43 +00:00
import { host } from '@/config.js';
import * as os from '@/os.js';
import { ColdDeviceStorage, defaultStore } from '@/store.js';
import { addTheme } from '@/theme-store.js';
2023-09-19 07:37:43 +00:00
import { i18n } from '@/i18n.js';
import { useLeaveGuard } from '@/scripts/use-leave-guard.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
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' },
];
const theme = ref<Partial<Theme>>({
base: 'light',
props: lightTheme.props,
});
const description = ref<string | null>(null);
const themeCode = ref<string | null>(null);
const changed = ref(false);
useLeaveGuard(changed);
function setBgColor(color: typeof bgColors[number]) {
if (theme.value.base !== color.kind) {
const base = color.kind === 'dark' ? darkTheme : lightTheme;
for (const prop of Object.keys(base.props)) {
if (prop === 'accent') continue;
if (prop === 'fg') continue;
theme.value.props[prop] = base.props[prop];
}
}
theme.value.base = color.kind;
theme.value.props.bg = color.color;
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()));
if (matchedFgColor) setFgColor(matchedFgColor);
}
}
2021-01-16 04:47:07 +00:00
function setAccentColor(color) {
theme.value.props.accent = color;
}
2021-01-16 04:47:07 +00:00
function setFgColor(color) {
theme.value.props.fg = theme.value.base === 'light' ? color.forLight : color.forDark;
}
2021-02-06 09:06:54 +00:00
function apply() {
themeCode.value = JSON5.stringify(theme.value, null, '\t');
applyTheme(theme.value, false);
changed.value = true;
}
2021-02-06 09:06:54 +00:00
function applyThemeCode() {
let parsed;
try {
parsed = JSON5.parse(themeCode.value);
} catch (err) {
os.alert({
type: 'error',
text: i18n.ts._theme.invalid,
});
return;
}
theme.value = parsed;
}
async function saveAs() {
const { canceled, result: name } = await os.inputText({
title: i18n.ts.name,
refactor: frontendのcomponentsの型エラーを改善 (#12926) * add: safeFloatParserを追加 * fix: 欠けていた型を追加 * refactor: pageBlockTypesをjson-schemaに移植 * refactor: components/global内の型エラーが出ている箇所を修正 * lint: fix null check style * refactor: fix type error * refactor: fix some type errors * fix: 翻訳が抜けていた箇所を修正 * refactor: getJsonSchemaで正しいスキーマが返されるように修正 * fix: MkChartの型エラーとbytesオプションが機能していない問題を修正 * fix(misskey-js): `drive`->`folderUpdated`のpayloadの型が間違っていたのを修正 * refactor: fix some type errors * change: Captcha読み込み中の文言をLoadingに変更 * refactor(backend/misskey-js): MainEventの型を改善 * refactor: chartjs-plugin-gradientが二重でpluginに登録されていたのを修正 * update: misskey-js.api.md * refactor: fix some type errors * fix: backendのtypecheckが落ちていたのを修正 * update: misskey-js.api.md * add: json-schemaのnoteにpollの型定義を追加 * refactor: noteのjson-schemaの型を改善 * refactor: MkPoll * refactor: fix some type errors * change: UserLiteにisLockedを持たせるように * fix: notificationスキーマにroleが含まれていないのを修正 * Revert "change: UserLiteにisLockedを持たせるように" This reverts commit 1bb0c8e7a9b19a4e9f21bf7381712b98f27672a5. * fix: フォロー通知から鍵垢へのフォローを行うと処理中のまま止まってしまう問題を修正 * refactor: noteスキーマのvisibilityにenumを追加 * change: deepCloneのCloneableTypeにundefinedを追加 * refactor: fix some type errors * refactor: `allowEmpty: false`を使用していた箇所を`minLength: 1`に置き換え * enhance: API 'retension' のresponseの型を追加 * fix: Chart関連のtooltipが正しい位置に表示されない問題を修正 * refactor: fix some type errors * fix: 型情報が不足していたのを修正 * enhance: announcementスキーマにenumを追加 * enhance: ロールポリシーの型定義をRoleServiceからjson-schemaに移植 * refactor: policiesを`ref: RolePolicies`に統一 * fix: API `meta` のレスポンスの型にpoliciesが含まれていないのを修正 * refactor: fix some type errors * fix: backendのlintが落ちているのを修正 * fix: MkFoldableSectionの開閉時のanimationが適用されていない問題を修正 * fix: backendのtypecheckが落ちているのを修正 * update: run build-misskey-js-with-types * fix: MkDialogのmount時に文字数制限の判定が行われない問題を修正 * update: CHANGELOG.md * refactor: MkUserSelectDialogの型を改善 * fix: deepCloneでundefinedはcloneしないように (#9207) * change: frontendのcloneをbackend側にも反映 * update: CHANGELOG.md * fix: RoleServiceからPackを通して型RolePoliciesに依存させないように * Update packages/frontend/src/scripts/get-note-summary.ts * revert RoleService.ts changes * change: optional chaining -> non-null assertion * remove: unused import * fix: propsで渡されたuserがUserLiteの場合に意図しない動作になってしまうのを修正 * change: fix null check style * refactor: fix type error * change: fix null check style * Update packages/frontend/src/components/MkDrive.vue Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * refactor: css moduleでglobalを使わないように * refactor: roleのiconUrlは必ず存在するものとして扱うように * enhance: MenuButtonのactiveにcomputedを受け付けられるように * Update packages/frontend/src/components/MkNotePreview.vue * Update MkWindow.vue * refactor: notification.noteは必ず存在するものとして扱うように * Update packages/frontend/src/components/MkNotification.vue Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * fix: MkSignupDialogでdoneのemit時にresを含んでいなかったのを修正 * Update packages/frontend/src/scripts/clone.ts Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> * refactor: 不要な返り値の型を削除 * refactor: 不要なnullチェックを削除 * update: misskey-js-autogen * update: clone.ts * refactor * Update MkNotification.vue * Update MkNotification.vue * :v: * Update MkNotification.vue * Update MkNotification.vue * Update MkNotification.vue * Update MkNotifications.vue * Update MkUserSetupDialog.Profile.vue * Update MkUserCardMini.vue * :v: * Update MkMenu.vue --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2024-01-30 10:53:53 +00:00
minLength: 1,
});
if (canceled) return;
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);
if (defaultStore.state.darkMode) {
ColdDeviceStorage.set('darkTheme', theme.value);
} else {
ColdDeviceStorage.set('lightTheme', theme.value);
}
changed.value = false;
os.alert({
type: 'success',
text: i18n.tsx._theme.installed({ name: theme.value.name }),
});
}
watch(theme, apply, { deep: true });
const headerActions = computed(() => [{
2022-06-23 15:47:55 +00:00
asFullButton: true,
2023-09-30 19:53:52 +00:00
icon: 'ph-check ph-bold ph-lg',
2022-06-23 15:47:55 +00:00
text: i18n.ts.saveAs,
handler: saveAs,
}]);
const headerTabs = computed(() => []);
definePageMetadata(() => ({
title: i18n.ts.themeEditor,
2023-09-30 22:46:42 +00:00
icon: 'ph-palette ph-bold ph-lg',
}));
</script>
<style lang="scss" scoped>
2021-01-09 08:18:45 +00:00
.cwepdizn {
2022-01-04 13:42:04 +00:00
::v-deep(.cwepdizn-colors) {
text-align: center;
> .row {
> .color {
display: inline-block;
position: relative;
width: 64px;
height: 64px;
border-radius: var(--radius-sm);
2022-01-04 13:42:04 +00:00
> .preview {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
width: 42px;
height: 42px;
border-radius: var(--radius-xs);
2022-01-04 13:42:04 +00:00
box-shadow: 0 2px 4px rgb(0 0 0 / 30%);
transition: transform 0.15s ease;
}
2021-01-09 08:18:45 +00:00
2022-01-04 13:42:04 +00:00
&:hover {
2021-01-09 08:18:45 +00:00
> .preview {
2022-01-04 13:42:04 +00:00
transform: scale(1.1);
}
2022-01-04 13:42:04 +00:00
}
2022-01-04 13:42:04 +00:00
&.active {
box-shadow: 0 0 0 2px var(--divider) inset;
}
2022-01-04 13:42:04 +00:00
&.rounded {
border-radius: var(--radius-ellipse);
2022-01-04 13:42:04 +00:00
> .preview {
border-radius: var(--radius-ellipse);
}
2022-01-04 13:42:04 +00:00
}
2021-01-09 08:18:45 +00:00
2022-01-04 13:42:04 +00:00
&.char {
line-height: 42px;
2021-01-09 08:18:45 +00:00
}
}
}
}
}
</style>