fix(frontend/frontend-embed): インポートパス・テーマまわりなどの修正 (#14535)

* fix(frontend/frontend-embed): wrong imports

* enhance(frontend-embed): サーバーデフォルトのテーマがある場合はそちらを利用するように

* 🎨

* 🎨

* 🎨
This commit is contained in:
かっこかり 2024-09-10 16:14:02 +09:00 committed by GitHub
parent 672779a15f
commit f393b6b898
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 42 additions and 20 deletions

View file

@ -10,23 +10,42 @@ import '@tabler/icons-webfont/dist/tabler-icons.scss';
import '@/style.scss'; import '@/style.scss';
import { createApp, defineAsyncComponent } from 'vue'; import { createApp, defineAsyncComponent } from 'vue';
import lightTheme from '@@/themes/l-light.json5'; import defaultLightTheme from '@@/themes/l-light.json5';
import darkTheme from '@@/themes/d-dark.json5'; import defaultDarkTheme from '@@/themes/d-dark.json5';
import { MediaProxy } from '@@/js/media-proxy.js'; import { MediaProxy } from '@@/js/media-proxy.js';
import { applyTheme } from './theme.js'; import { applyTheme, assertIsTheme } from '@/theme.js';
import { fetchCustomEmojis } from './custom-emojis.js'; import { fetchCustomEmojis } from '@/custom-emojis.js';
import { DI } from './di.js'; import { DI } from '@/di.js';
import { serverMetadata } from './server-metadata.js'; import { serverMetadata } from '@/server-metadata.js';
import { url } from './config.js'; import { url } from '@/config.js';
import { parseEmbedParams } from '@@/js/embed-page.js'; import { parseEmbedParams } from '@@/js/embed-page.js';
import { postMessageToParentWindow, setIframeId } from '@/post-message.js'; import { postMessageToParentWindow, setIframeId } from '@/post-message.js';
console.info('Misskey Embed'); import type { Theme } from '@/theme.js';
console.log('Misskey Embed');
const params = new URLSearchParams(location.search); const params = new URLSearchParams(location.search);
const embedParams = parseEmbedParams(params); const embedParams = parseEmbedParams(params);
console.info(embedParams); if (_DEV_) console.log(embedParams);
function parseThemeOrNull(theme: string | null): Theme | null {
if (theme == null) return null;
try {
const parsed = JSON.parse(theme);
if (assertIsTheme(parsed)) {
return parsed;
} else {
return null;
}
} catch (err) {
return null;
}
}
const lightTheme = parseThemeOrNull(serverMetadata.defaultLightTheme) ?? defaultLightTheme;
const darkTheme = parseThemeOrNull(serverMetadata.defaultDarkTheme) ?? defaultDarkTheme;
if (embedParams.colorMode === 'dark') { if (embedParams.colorMode === 'dark') {
applyTheme(darkTheme); applyTheme(darkTheme);

View file

@ -135,7 +135,7 @@ misskeyApi('clips/show', {
.instanceIcon { .instanceIcon {
height: 24px; height: 24px;
border-radius: 4px; border-radius: 3px;
} }
} }
</style> </style>

View file

@ -119,7 +119,7 @@ function top(ev: MouseEvent) {
.instanceIcon { .instanceIcon {
height: 24px; height: 24px;
border-radius: 4px; border-radius: 3px;
} }
} }
</style> </style>

View file

@ -132,7 +132,7 @@ misskeyApi('users/show', {
.instanceIcon { .instanceIcon {
height: 24px; height: 24px;
border-radius: 4px; border-radius: 3px;
} }
} }
</style> </style>

View file

@ -3,13 +3,14 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import * as Misskey from 'misskey-js';
import { misskeyApi } from '@/misskey-api.js'; import { misskeyApi } from '@/misskey-api.js';
const providedMetaEl = document.getElementById('misskey_meta'); const providedMetaEl = document.getElementById('misskey_meta');
const _serverMetadata = (providedMetaEl && providedMetaEl.textContent) ? JSON.parse(providedMetaEl.textContent) : null; const _serverMetadata: Misskey.entities.MetaDetailed | null = (providedMetaEl && providedMetaEl.textContent) ? JSON.parse(providedMetaEl.textContent) : null;
// NOTE: devモードのときしか _serverMetadata が null になることは無い // NOTE: devモードのときしか _serverMetadata が null になることは無い
export const serverMetadata = _serverMetadata ?? await misskeyApi('meta', { export const serverMetadata: Misskey.entities.MetaDetailed = _serverMetadata ?? await misskeyApi('meta', {
detail: true, detail: true,
}); });

View file

@ -26,6 +26,10 @@ export type Theme = {
let timeout: number | null = null; let timeout: number | null = null;
export function assertIsTheme(theme: Record<string, unknown>): theme is Theme {
return typeof theme === 'object' && theme !== null && 'id' in theme && 'name' in theme && 'author' in theme && 'props' in theme;
}
export function applyTheme(theme: Theme, persist = true) { export function applyTheme(theme: Theme, persist = true) {
if (timeout) window.clearTimeout(timeout); if (timeout) window.clearTimeout(timeout);
@ -35,8 +39,6 @@ export function applyTheme(theme: Theme, persist = true) {
document.documentElement.classList.remove('_themeChanging_'); document.documentElement.classList.remove('_themeChanging_');
}, 1000); }, 1000);
const colorScheme = theme.base === 'dark' ? 'dark' : 'light';
// Deep copy // Deep copy
const _theme = JSON.parse(JSON.stringify(theme)); const _theme = JSON.parse(JSON.stringify(theme));
@ -58,7 +60,7 @@ export function applyTheme(theme: Theme, persist = true) {
document.documentElement.style.setProperty(`--${k}`, v.toString()); document.documentElement.style.setProperty(`--${k}`, v.toString());
} }
document.documentElement.style.setProperty('color-scheme', colorScheme); // iframeを正常に透過させるために、cssのcolor-schemeは `light dark;` 固定にしてある。style.scss参照
} }
function compile(theme: Theme): Record<string, string> { function compile(theme: Theme): Record<string, string> {

View file

@ -40,7 +40,7 @@ import XNotFound from '@/pages/not-found.vue';
const page = location.pathname.split('/')[2]; const page = location.pathname.split('/')[2];
const contentId = location.pathname.split('/')[3]; const contentId = location.pathname.split('/')[3];
console.log(page, contentId); if (_DEV_) console.log(page, contentId);
const embedParams = inject(DI.embedParams, defaultEmbedParams); const embedParams = inject(DI.embedParams, defaultEmbedParams);

View file

@ -13,7 +13,7 @@ SPDX-License-Identifier: AGPL-3.0-only
@close="cancel()" @close="cancel()"
@closed="$emit('closed')" @closed="$emit('closed')"
> >
<template #header>{{ i18n.ts._embedCodeGen.title }}</template> <template #header><i class="ti ti-code"></i> {{ i18n.ts._embedCodeGen.title }}</template>
<div :class="$style.embedCodeGenRoot"> <div :class="$style.embedCodeGenRoot">
<Transition <Transition

View file

@ -52,7 +52,7 @@ export const getBuiltinThemes = () => Promise.all(
'd-cherry', 'd-cherry',
'd-ice', 'd-ice',
'd-u0', 'd-u0',
].map(name => import(`@/themes/${name}.json5`).then(({ default: _default }): Theme => _default)), ].map(name => import(`@@/themes/${name}.json5`).then(({ default: _default }): Theme => _default)),
); );
export const getBuiltinThemesRef = () => { export const getBuiltinThemesRef = () => {