2023-05-14 05:23:39 +02:00
|
|
|
|
import { VNode, h } from 'vue';
|
2021-04-02 03:36:11 +02:00
|
|
|
|
import * as mfm from 'mfm-js';
|
2023-05-14 05:23:39 +02:00
|
|
|
|
import * as Misskey from 'misskey-js';
|
2022-08-30 17:24:33 +02:00
|
|
|
|
import MkUrl from '@/components/global/MkUrl.vue';
|
|
|
|
|
import MkLink from '@/components/MkLink.vue';
|
|
|
|
|
import MkMention from '@/components/MkMention.vue';
|
|
|
|
|
import MkEmoji from '@/components/global/MkEmoji.vue';
|
2023-01-26 07:48:12 +01:00
|
|
|
|
import MkCustomEmoji from '@/components/global/MkCustomEmoji.vue';
|
2023-09-16 15:16:47 +02:00
|
|
|
|
import MkEmojiKitchen from '@/components/global/MkEmojiKitchen.vue';
|
2022-08-30 17:24:33 +02:00
|
|
|
|
import MkCode from '@/components/MkCode.vue';
|
|
|
|
|
import MkGoogle from '@/components/MkGoogle.vue';
|
|
|
|
|
import MkSparkle from '@/components/MkSparkle.vue';
|
|
|
|
|
import MkA from '@/components/global/MkA.vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
|
import { host } from '@/config';
|
2023-02-11 03:21:06 +01:00
|
|
|
|
import { defaultStore } from '@/store';
|
2023-09-16 15:16:47 +02:00
|
|
|
|
import { mixEmoji } from '@/scripts/emojiKitchen/emojiMixer';
|
2023-10-12 05:54:09 +02:00
|
|
|
|
import MkRuby from "@/components/global/MkRuby.vue";
|
2023-10-28 05:41:17 +02:00
|
|
|
|
import { nyaize as doNyaize } from '@/scripts/nyaize.js';
|
2023-11-02 08:51:03 +01:00
|
|
|
|
import { uhoize as doUhoize } from '@/scripts/uhoize.js';
|
|
|
|
|
import {ID, Instance} from "misskey-js/built/entities.js";
|
2018-03-31 14:41:08 +02:00
|
|
|
|
|
2023-01-14 04:43:54 +01:00
|
|
|
|
const QUOTE_STYLE = `
|
|
|
|
|
display: block;
|
|
|
|
|
margin: 8px;
|
|
|
|
|
padding: 6px 0 6px 12px;
|
|
|
|
|
color: var(--fg);
|
|
|
|
|
border-left: solid 3px var(--fg);
|
|
|
|
|
opacity: 0.7;
|
|
|
|
|
`.split('\n').join(' ');
|
2023-09-16 15:16:47 +02:00
|
|
|
|
const colorRegexp = /^([0-9a-f]{3,4}?|[0-9a-f]{6}?|[0-9a-f]{8}?)$/i;
|
|
|
|
|
function checkColorHex(text: string) {
|
2023-10-28 09:06:07 +02:00
|
|
|
|
return colorRegexp.test(text);
|
2023-09-16 15:16:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const gradientCounterRegExp = /^(color|step)(\d+)/;
|
|
|
|
|
|
|
|
|
|
function toGradientText(args: Record<string, string>) {
|
2023-10-28 09:06:07 +02:00
|
|
|
|
const colors: { index: number; step?: string, color?: string }[] = [];
|
|
|
|
|
for (const k in args) {
|
|
|
|
|
const matches = k.match(gradientCounterRegExp);
|
|
|
|
|
if (matches == null) continue;
|
|
|
|
|
const mindex = parseInt(matches[2]);
|
|
|
|
|
let i = colors.findIndex(v => v.index === mindex);
|
|
|
|
|
if (i === -1) {
|
|
|
|
|
i = colors.length;
|
|
|
|
|
colors.push({ index: mindex });
|
|
|
|
|
}
|
|
|
|
|
colors[i][matches[1]] = args[k];
|
|
|
|
|
}
|
|
|
|
|
let deg = parseFloat(args.deg || '90');
|
|
|
|
|
let res = `linear-gradient(${deg}deg`;
|
|
|
|
|
for (const colorProp of colors.sort((a, b) => a.index - b.index)) {
|
|
|
|
|
let color = colorProp.color;
|
|
|
|
|
if (!color || !checkColorHex(color)) color = 'f00';
|
|
|
|
|
let step = parseFloat(colorProp.step ?? '');
|
|
|
|
|
let stepText = isNaN(step) ? '' : ` ${step}%`;
|
|
|
|
|
res += `, #${color}${stepText}`;
|
|
|
|
|
}
|
|
|
|
|
return res + ')';
|
2023-09-16 15:16:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-14 04:43:54 +01:00
|
|
|
|
|
2023-10-28 05:41:17 +02:00
|
|
|
|
type MfmProps = {
|
2023-05-14 05:23:39 +02:00
|
|
|
|
text: string;
|
|
|
|
|
plain?: boolean;
|
|
|
|
|
nowrap?: boolean;
|
2023-11-02 08:51:03 +01:00
|
|
|
|
author?: {
|
|
|
|
|
id: ID;
|
|
|
|
|
username: string;
|
|
|
|
|
host: string | null;
|
|
|
|
|
name: string | null;
|
|
|
|
|
onlineStatus: 'online' | 'active' | 'offline' | 'unknown';
|
|
|
|
|
avatarUrl: string;
|
|
|
|
|
avatarBlurhash: string;
|
|
|
|
|
avatarDecorations: {
|
|
|
|
|
id: ID;
|
|
|
|
|
url: string;
|
|
|
|
|
angle?: number;
|
|
|
|
|
flipH?: boolean;
|
|
|
|
|
}[];
|
|
|
|
|
emojis: {
|
|
|
|
|
name: string;
|
|
|
|
|
url: string;
|
|
|
|
|
}[];
|
|
|
|
|
instance?: {
|
|
|
|
|
name: Instance['name'];
|
|
|
|
|
softwareName: Instance['softwareName'];
|
|
|
|
|
softwareVersion: Instance['softwareVersion'];
|
|
|
|
|
iconUrl: Instance['iconUrl'];
|
|
|
|
|
faviconUrl: Instance['faviconUrl'];
|
|
|
|
|
themeColor: Instance['themeColor'];
|
|
|
|
|
};
|
|
|
|
|
isGorilla?: boolean;
|
|
|
|
|
isCat?: boolean;
|
|
|
|
|
isBot?: boolean;};
|
2023-10-28 05:41:17 +02:00
|
|
|
|
i?: Misskey.entities.UserLite | null;
|
2023-05-14 05:23:39 +02:00
|
|
|
|
isNote?: boolean;
|
|
|
|
|
emojiUrls?: string[];
|
|
|
|
|
rootScale?: number;
|
2023-10-28 05:41:17 +02:00
|
|
|
|
nyaize: boolean | 'account';
|
2023-11-02 08:51:03 +01:00
|
|
|
|
uhoize: boolean | 'account';
|
2023-11-01 02:23:20 +01:00
|
|
|
|
parsedNodes?: mfm.MfmNode[] | null;
|
2023-11-04 10:27:22 +01:00
|
|
|
|
enableEmojiMenu?: boolean;
|
|
|
|
|
enableEmojiMenuReaction?: boolean;
|
2023-10-28 05:41:17 +02:00
|
|
|
|
};
|
2018-03-31 14:41:08 +02:00
|
|
|
|
|
2023-10-28 05:41:17 +02:00
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
|
|
|
export default function(props: MfmProps) {
|
|
|
|
|
const isNote = props.isNote ?? true;
|
|
|
|
|
const shouldNyaize = props.nyaize ? props.nyaize === 'account' ? props.author?.isCat : false : false;
|
2023-11-02 08:51:03 +01:00
|
|
|
|
const shouldUhoize = props.nyaize ? props.nyaize === 'account' ? props.author?.isGorilla : false : false;
|
|
|
|
|
console.log(shouldUhoize, props.nyaize,props.author?.isGorilla)
|
2023-10-28 05:41:17 +02:00
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
2023-05-14 05:23:39 +02:00
|
|
|
|
if (props.text == null || props.text === '') return;
|
2018-11-20 21:11:00 +01:00
|
|
|
|
|
2023-11-01 02:23:20 +01:00
|
|
|
|
const rootAst = props.parsedNodes ?? (props.plain ? mfm.parseSimple : mfm.parse)(props.text);
|
2018-03-31 14:41:08 +02:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
const validTime = (t: string | null | undefined) => {
|
2023-09-16 15:16:47 +02:00
|
|
|
|
if (t == null || typeof t === 'boolean') return null;
|
2023-05-14 05:23:39 +02:00
|
|
|
|
return t.match(/^[0-9.]+s$/) ? t : null;
|
|
|
|
|
};
|
2021-01-03 04:51:50 +01:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
const useAnim = defaultStore.state.advancedMfm && defaultStore.state.animatedMfm;
|
2023-02-11 03:31:18 +01:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
/**
|
|
|
|
|
* Gen Vue Elements from MFM AST
|
|
|
|
|
* @param ast MFM AST
|
|
|
|
|
* @param scale How times large the text is
|
2023-10-28 05:41:17 +02:00
|
|
|
|
* @param disableNyaize Whether nyaize is disabled or not
|
2023-11-02 08:51:03 +01:00
|
|
|
|
* @param disableUhoize
|
2023-05-14 05:23:39 +02:00
|
|
|
|
*/
|
2023-11-02 08:51:03 +01:00
|
|
|
|
const genEl = (ast: mfm.MfmNode[], scale: number, disableNyaize = false, disableUhoize = false) => ast.map((token): VNode | string | (VNode | string)[] => {
|
2023-05-14 05:23:39 +02:00
|
|
|
|
switch (token.type) {
|
|
|
|
|
case 'text': {
|
2023-10-19 04:42:17 +02:00
|
|
|
|
let text = token.props.text.replace(/(\r\n|\n|\r)/g, '\n');
|
2023-10-28 05:41:17 +02:00
|
|
|
|
if (!disableNyaize && shouldNyaize) {
|
|
|
|
|
text = doNyaize(text);
|
2023-10-19 04:42:17 +02:00
|
|
|
|
}
|
2023-11-02 08:51:03 +01:00
|
|
|
|
if (!disableUhoize && shouldUhoize) {
|
|
|
|
|
text = doUhoize(text);
|
|
|
|
|
}
|
2023-05-14 05:23:39 +02:00
|
|
|
|
if (!props.plain) {
|
|
|
|
|
const res: (VNode | string)[] = [];
|
|
|
|
|
for (const t of text.split('\n')) {
|
|
|
|
|
res.push(h('br'));
|
|
|
|
|
res.push(t);
|
2018-03-31 14:41:08 +02:00
|
|
|
|
}
|
2023-05-14 05:23:39 +02:00
|
|
|
|
res.shift();
|
|
|
|
|
return res;
|
|
|
|
|
} else {
|
|
|
|
|
return [text.replace(/\n/g, ' ')];
|
2018-08-05 12:20:26 +02:00
|
|
|
|
}
|
2023-05-14 05:23:39 +02:00
|
|
|
|
}
|
2018-03-31 14:41:08 +02:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'bold': {
|
|
|
|
|
return [h('b', genEl(token.children, scale))];
|
|
|
|
|
}
|
2018-08-03 16:27:37 +02:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'strike': {
|
|
|
|
|
return [h('del', genEl(token.children, scale))];
|
|
|
|
|
}
|
2018-12-03 17:28:21 +01:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'italic': {
|
|
|
|
|
return h('i', {
|
|
|
|
|
style: 'font-style: oblique;',
|
|
|
|
|
}, genEl(token.children, scale));
|
|
|
|
|
}
|
2018-12-05 09:39:26 +01:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'fn': {
|
|
|
|
|
// TODO: CSSを文字列で組み立てていくと token.props.args.~~~ 経由でCSSインジェクションできるのでよしなにやる
|
|
|
|
|
let style;
|
|
|
|
|
switch (token.props.name) {
|
|
|
|
|
case 'tada': {
|
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '1s';
|
|
|
|
|
style = 'font-size: 150%;' + (useAnim ? `animation: tada ${speed} linear infinite both;` : '');
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'jelly': {
|
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '1s';
|
|
|
|
|
style = (useAnim ? `animation: mfm-rubberBand ${speed} linear infinite both;` : '');
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'twitch': {
|
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '0.5s';
|
|
|
|
|
style = useAnim ? `animation: mfm-twitch ${speed} ease infinite;` : '';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'shake': {
|
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '0.5s';
|
|
|
|
|
style = useAnim ? `animation: mfm-shake ${speed} ease infinite;` : '';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'spin': {
|
|
|
|
|
const direction =
|
|
|
|
|
token.props.args.left ? 'reverse' :
|
|
|
|
|
token.props.args.alternate ? 'alternate' :
|
|
|
|
|
'normal';
|
|
|
|
|
const anime =
|
|
|
|
|
token.props.args.x ? 'mfm-spinX' :
|
|
|
|
|
token.props.args.y ? 'mfm-spinY' :
|
|
|
|
|
'mfm-spin';
|
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '1.5s';
|
|
|
|
|
style = useAnim ? `animation: ${anime} ${speed} linear infinite; animation-direction: ${direction};` : '';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'jump': {
|
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '0.75s';
|
|
|
|
|
style = useAnim ? `animation: mfm-jump ${speed} linear infinite;` : '';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'bounce': {
|
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '0.75s';
|
|
|
|
|
style = useAnim ? `animation: mfm-bounce ${speed} linear infinite; transform-origin: center bottom;` : '';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'flip': {
|
|
|
|
|
const transform =
|
|
|
|
|
(token.props.args.h && token.props.args.v) ? 'scale(-1, -1)' :
|
|
|
|
|
token.props.args.v ? 'scaleY(-1)' :
|
|
|
|
|
'scaleX(-1)';
|
|
|
|
|
style = `transform: ${transform};`;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'x2': {
|
|
|
|
|
return h('span', {
|
|
|
|
|
class: defaultStore.state.advancedMfm ? 'mfm-x2' : '',
|
|
|
|
|
}, genEl(token.children, scale * 2));
|
|
|
|
|
}
|
|
|
|
|
case 'x3': {
|
|
|
|
|
return h('span', {
|
|
|
|
|
class: defaultStore.state.advancedMfm ? 'mfm-x3' : '',
|
|
|
|
|
}, genEl(token.children, scale * 3));
|
|
|
|
|
}
|
|
|
|
|
case 'x4': {
|
|
|
|
|
return h('span', {
|
|
|
|
|
class: defaultStore.state.advancedMfm ? 'mfm-x4' : '',
|
|
|
|
|
}, genEl(token.children, scale * 4));
|
|
|
|
|
}
|
|
|
|
|
case 'font': {
|
|
|
|
|
const family =
|
|
|
|
|
token.props.args.serif ? 'serif' :
|
|
|
|
|
token.props.args.monospace ? 'monospace' :
|
|
|
|
|
token.props.args.cursive ? 'cursive' :
|
|
|
|
|
token.props.args.fantasy ? 'fantasy' :
|
|
|
|
|
token.props.args.emoji ? 'emoji' :
|
|
|
|
|
token.props.args.math ? 'math' :
|
|
|
|
|
null;
|
|
|
|
|
if (family) style = `font-family: ${family};`;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'blur': {
|
2023-09-16 15:16:47 +02:00
|
|
|
|
const radius = parseFloat(token.props.args.rad ?? '6');
|
2023-05-14 05:23:39 +02:00
|
|
|
|
return h('span', {
|
|
|
|
|
class: '_mfm_blur_',
|
2023-09-16 15:16:47 +02:00
|
|
|
|
style: `--blur-px: ${radius}px;`
|
2023-05-14 05:23:39 +02:00
|
|
|
|
}, genEl(token.children, scale));
|
|
|
|
|
}
|
|
|
|
|
case 'rainbow': {
|
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '1s';
|
2023-09-16 15:16:47 +02:00
|
|
|
|
style = useAnim ? `animation: mfm-rainbow ${speed} linear infinite;` : '';
|
2023-05-14 05:23:39 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'sparkle': {
|
|
|
|
|
if (!useAnim) {
|
|
|
|
|
return genEl(token.children, scale);
|
2023-01-14 00:52:32 +01:00
|
|
|
|
}
|
2023-05-14 05:23:39 +02:00
|
|
|
|
return h(MkSparkle, {}, genEl(token.children, scale));
|
|
|
|
|
}
|
|
|
|
|
case 'rotate': {
|
|
|
|
|
const degrees = parseFloat(token.props.args.deg ?? '90');
|
2023-09-16 15:16:47 +02:00
|
|
|
|
let rotateText = `rotate(${degrees}deg)`;
|
|
|
|
|
if (!token.props.args.deg && (token.props.args.x || token.props.args.y || token.props.args.z)) {
|
|
|
|
|
rotateText = '';
|
|
|
|
|
}
|
|
|
|
|
if (token.props.args.x) {
|
|
|
|
|
const degrees = parseFloat(token.props.args.x ?? '0');
|
|
|
|
|
rotateText += ` rotateX(${degrees}deg)`;
|
|
|
|
|
}
|
|
|
|
|
if (token.props.args.y) {
|
|
|
|
|
const degrees = parseFloat(token.props.args.y ?? '0');
|
|
|
|
|
rotateText += ` rotateY(${degrees}deg)`;
|
|
|
|
|
}
|
|
|
|
|
if (token.props.args.z) {
|
|
|
|
|
const degrees = parseFloat(token.props.args.z ?? '0');
|
|
|
|
|
rotateText += ` rotateZ(${degrees}deg)`;
|
|
|
|
|
}
|
|
|
|
|
style = `transform: ${rotateText}; transform-origin: center center;`;
|
2023-05-14 05:23:39 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'position': {
|
|
|
|
|
if (!defaultStore.state.advancedMfm) break;
|
|
|
|
|
const x = parseFloat(token.props.args.x ?? '0');
|
|
|
|
|
const y = parseFloat(token.props.args.y ?? '0');
|
|
|
|
|
style = `transform: translateX(${x}em) translateY(${y}em);`;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'scale': {
|
|
|
|
|
if (!defaultStore.state.advancedMfm) {
|
|
|
|
|
style = '';
|
2023-01-14 00:52:32 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2023-05-14 05:23:39 +02:00
|
|
|
|
const x = Math.min(parseFloat(token.props.args.x ?? '1'), 5);
|
|
|
|
|
const y = Math.min(parseFloat(token.props.args.y ?? '1'), 5);
|
2023-07-08 00:08:16 +02:00
|
|
|
|
style = `transform: scale(${x}, ${y});`;
|
2023-05-14 05:23:39 +02:00
|
|
|
|
scale = scale * Math.max(x, y);
|
|
|
|
|
break;
|
2020-11-07 15:41:21 +01:00
|
|
|
|
}
|
2023-09-16 15:16:47 +02:00
|
|
|
|
case 'skew': {
|
|
|
|
|
if (!defaultStore.state.advancedMfm) {
|
|
|
|
|
style = '';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
const x = parseFloat(token.props.args.x ?? '0');
|
|
|
|
|
const y = parseFloat(token.props.args.y ?? '0');
|
|
|
|
|
style = `transform: skew(${x}deg, ${y}deg);`;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'fgg': {
|
|
|
|
|
if (!defaultStore.state.advancedMfm) break;
|
|
|
|
|
style = `-webkit-background-clip: text; -webkit-text-fill-color: transparent; background-image: ${toGradientText(token.props.args)};`
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'fg': {
|
|
|
|
|
let color = token.props.args.color;
|
2023-09-16 15:16:47 +02:00
|
|
|
|
if (!checkColorHex(color)) color = 'f00';
|
2023-05-14 05:23:39 +02:00
|
|
|
|
style = `color: #${color};`;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-09-16 15:16:47 +02:00
|
|
|
|
case 'bgg': {
|
|
|
|
|
if (!defaultStore.state.advancedMfm) break;
|
|
|
|
|
style = `background-image: ${toGradientText(token.props.args)};`
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'bg': {
|
|
|
|
|
let color = token.props.args.color;
|
2023-09-16 15:16:47 +02:00
|
|
|
|
if (!checkColorHex(color)) color = 'f00';
|
2023-05-14 05:23:39 +02:00
|
|
|
|
style = `background-color: #${color};`;
|
|
|
|
|
break;
|
2020-11-09 14:32:01 +01:00
|
|
|
|
}
|
2023-09-16 15:16:47 +02:00
|
|
|
|
case 'clip': {
|
|
|
|
|
if (!defaultStore.state.advancedMfm) break;
|
|
|
|
|
|
|
|
|
|
let path = '';
|
|
|
|
|
if (token.props.args.circle) {
|
|
|
|
|
const percent = parseFloat(token.props.args.circle ?? '');
|
|
|
|
|
const percentText = isNaN(percent) ? '' : `${percent}%`;
|
|
|
|
|
path = `circle(${percentText})`;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const top = parseFloat(token.props.args.t ?? '0');
|
|
|
|
|
const bottom = parseFloat(token.props.args.b ?? '0');
|
|
|
|
|
const left = parseFloat(token.props.args.l ?? '0');
|
|
|
|
|
const right = parseFloat(token.props.args.r ?? '0');
|
|
|
|
|
path = `inset(${top}% ${right}% ${bottom}% ${left}%)`;
|
|
|
|
|
}
|
|
|
|
|
style = `clip-path: ${path};`;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'move': {
|
|
|
|
|
const speed = validTime(token.props.args.speed) ?? '1s';
|
|
|
|
|
const fromX = parseFloat(token.props.args.fromx ?? '0');
|
|
|
|
|
const fromY = parseFloat(token.props.args.fromy ?? '0');
|
|
|
|
|
const toX = parseFloat(token.props.args.tox ?? '0');
|
|
|
|
|
const toY = parseFloat(token.props.args.toy ?? '0');
|
|
|
|
|
const ease =
|
|
|
|
|
token.props.args.ease ? 'ease' :
|
|
|
|
|
token.props.args.easein ? 'ease-in' :
|
|
|
|
|
token.props.args.easeout ? 'ease-out' :
|
|
|
|
|
token.props.args.easeinout ? 'ease-in-out' :
|
|
|
|
|
'linear';
|
|
|
|
|
const delay = validTime(token.props.args.delay) ?? '0s';
|
|
|
|
|
const direction =
|
|
|
|
|
token.props.args.rev && token.props.args.once ? 'reverse' :
|
|
|
|
|
token.props.args.rev ? 'alternate-reverse' :
|
|
|
|
|
token.props.args.once ? 'normal' :
|
|
|
|
|
'alternate';
|
|
|
|
|
style = useAnim ? `--move-fromX: ${fromX}em; --move-fromY: ${fromY}em; --move-toX: ${toX}em; --move-toY: ${toY}em; animation: ${speed} ${ease} ${delay} infinite ${direction} mfm-move;` : '';
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-10-12 05:54:09 +02:00
|
|
|
|
case 'ruby': {
|
|
|
|
|
if (token.children.length === 1 ){
|
|
|
|
|
const base = token.children[0].props.text.split(/[ ]+/);
|
|
|
|
|
if (base.length !== 2 ){
|
|
|
|
|
style = null;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return h(MkRuby,{
|
|
|
|
|
base:base[0],
|
|
|
|
|
text:base[1]
|
|
|
|
|
});
|
|
|
|
|
}else if(token.children.length === 2){
|
2023-10-12 08:25:41 +02:00
|
|
|
|
let txt,base;
|
2023-10-12 05:54:09 +02:00
|
|
|
|
console.log(token.children)
|
2023-10-12 08:25:41 +02:00
|
|
|
|
if (token.children[1].type === 'emojiCode'){
|
|
|
|
|
txt = token.children[1].props.name
|
|
|
|
|
}else if(token.children[1].type === 'unicodeEmoji'){
|
|
|
|
|
txt = token.children[1].props.emoji
|
|
|
|
|
}else {
|
|
|
|
|
txt = token.children[1].props.text
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (token.children[0].type === 'emojiCode'){
|
|
|
|
|
base = token.children[0].props.name
|
|
|
|
|
}else if(token.children[0].type === 'unicodeEmoji'){
|
|
|
|
|
base = token.children[0].props.emoji
|
|
|
|
|
}else {
|
|
|
|
|
base = token.children[0].props.text
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-12 05:54:09 +02:00
|
|
|
|
return h(MkRuby,{
|
|
|
|
|
base:base,
|
|
|
|
|
basetype:token.children[0].type,
|
|
|
|
|
text:txt,
|
|
|
|
|
});
|
|
|
|
|
}else{
|
|
|
|
|
style = null;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-16 15:16:47 +02:00
|
|
|
|
case 'mix': {
|
|
|
|
|
const ch = token.children;
|
|
|
|
|
if (ch.length != 2 || ch.some(c => c.type !== 'unicodeEmoji')) {
|
|
|
|
|
style = null;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const emoji1 = ch[0].props.emoji;
|
|
|
|
|
const emoji2 = ch[1].props.emoji;
|
|
|
|
|
|
|
|
|
|
const mixedEmojiUrl = mixEmoji(emoji1, emoji2);
|
|
|
|
|
if (!mixedEmojiUrl) {
|
|
|
|
|
style = null;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return h(MkEmojiKitchen, {
|
|
|
|
|
key: Math.random(),
|
|
|
|
|
name: emoji1 + emoji2,
|
|
|
|
|
normal: props.plain,
|
|
|
|
|
url: mixedEmojiUrl
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-08-05 12:20:26 +02:00
|
|
|
|
}
|
2023-05-14 05:23:39 +02:00
|
|
|
|
if (style == null) {
|
|
|
|
|
return h('span', {}, ['$[', token.props.name, ' ', ...genEl(token.children, scale), ']']);
|
|
|
|
|
} else {
|
|
|
|
|
return h('span', {
|
|
|
|
|
style: 'display: inline-block; ' + style,
|
|
|
|
|
}, genEl(token.children, scale));
|
2018-12-05 12:11:54 +01:00
|
|
|
|
}
|
2023-05-14 05:23:39 +02:00
|
|
|
|
}
|
2018-12-05 12:11:54 +01:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'small': {
|
|
|
|
|
return [h('small', {
|
|
|
|
|
style: 'opacity: 0.7;',
|
|
|
|
|
}, genEl(token.children, scale))];
|
|
|
|
|
}
|
2018-11-25 05:36:40 +01:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'center': {
|
|
|
|
|
return [h('div', {
|
|
|
|
|
style: 'text-align:center;',
|
|
|
|
|
}, genEl(token.children, scale))];
|
|
|
|
|
}
|
2018-03-31 14:41:08 +02:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'url': {
|
|
|
|
|
return [h(MkUrl, {
|
|
|
|
|
key: Math.random(),
|
|
|
|
|
url: token.props.url,
|
|
|
|
|
rel: 'nofollow noopener',
|
|
|
|
|
})];
|
|
|
|
|
}
|
2018-03-31 14:41:08 +02:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'link': {
|
|
|
|
|
return [h(MkLink, {
|
|
|
|
|
key: Math.random(),
|
|
|
|
|
url: token.props.url,
|
|
|
|
|
rel: 'nofollow noopener',
|
2023-10-19 04:42:17 +02:00
|
|
|
|
}, genEl(token.children, scale, true))];
|
2023-05-14 05:23:39 +02:00
|
|
|
|
}
|
2018-03-31 14:41:08 +02:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'mention': {
|
|
|
|
|
return [h(MkMention, {
|
|
|
|
|
key: Math.random(),
|
2023-07-16 07:21:05 +02:00
|
|
|
|
host: (token.props.host == null && props.author && props.author.host != null ? props.author.host : token.props.host) ?? host,
|
2023-05-14 05:23:39 +02:00
|
|
|
|
username: token.props.username,
|
|
|
|
|
})];
|
|
|
|
|
}
|
|
|
|
|
case 'hashtag': {
|
|
|
|
|
return [h(MkA, {
|
|
|
|
|
key: Math.random(),
|
|
|
|
|
to: isNote ? `/tags/${encodeURIComponent(token.props.hashtag)}` : `/user-tags/${encodeURIComponent(token.props.hashtag)}`,
|
|
|
|
|
style: 'color:var(--hashtag);',
|
|
|
|
|
}, `#${token.props.hashtag}`)];
|
|
|
|
|
}
|
2018-03-31 14:41:08 +02:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'blockCode': {
|
|
|
|
|
return [h(MkCode, {
|
|
|
|
|
key: Math.random(),
|
|
|
|
|
code: token.props.code,
|
|
|
|
|
lang: token.props.lang,
|
|
|
|
|
})];
|
|
|
|
|
}
|
2018-03-31 14:41:08 +02:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'inlineCode': {
|
|
|
|
|
return [h(MkCode, {
|
|
|
|
|
key: Math.random(),
|
|
|
|
|
code: token.props.code,
|
|
|
|
|
inline: true,
|
|
|
|
|
})];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case 'quote': {
|
|
|
|
|
if (!props.nowrap) {
|
|
|
|
|
return [h('div', {
|
|
|
|
|
style: QUOTE_STYLE,
|
2023-10-19 04:42:17 +02:00
|
|
|
|
}, genEl(token.children, scale, true))];
|
2023-05-14 05:23:39 +02:00
|
|
|
|
} else {
|
|
|
|
|
return [h('span', {
|
|
|
|
|
style: QUOTE_STYLE,
|
2023-10-19 04:42:17 +02:00
|
|
|
|
}, genEl(token.children, scale, true))];
|
2018-08-05 12:20:26 +02:00
|
|
|
|
}
|
2023-05-14 05:23:39 +02:00
|
|
|
|
}
|
2018-03-31 14:41:08 +02:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'emojiCode': {
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
|
|
|
if (props.author?.host == null) {
|
|
|
|
|
return [h(MkCustomEmoji, {
|
|
|
|
|
key: Math.random(),
|
|
|
|
|
name: token.props.name,
|
|
|
|
|
normal: props.plain,
|
|
|
|
|
host: null,
|
|
|
|
|
useOriginalSize: scale >= 2.5,
|
2023-11-04 10:27:22 +01:00
|
|
|
|
menu: props.enableEmojiMenu,
|
|
|
|
|
menuReaction: props.enableEmojiMenuReaction,
|
2023-05-14 05:23:39 +02:00
|
|
|
|
})];
|
|
|
|
|
} else {
|
2023-01-26 07:48:12 +01:00
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
2023-05-14 05:23:39 +02:00
|
|
|
|
if (props.emojiUrls && (props.emojiUrls[token.props.name] == null)) {
|
|
|
|
|
return [h('span', `:${token.props.name}:`)];
|
|
|
|
|
} else {
|
2023-01-26 07:48:12 +01:00
|
|
|
|
return [h(MkCustomEmoji, {
|
|
|
|
|
key: Math.random(),
|
|
|
|
|
name: token.props.name,
|
2023-05-14 05:23:39 +02:00
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
|
|
|
url: props.emojiUrls ? props.emojiUrls[token.props.name] : null,
|
|
|
|
|
normal: props.plain,
|
|
|
|
|
host: props.author.host,
|
2023-04-12 03:58:56 +02:00
|
|
|
|
useOriginalSize: scale >= 2.5,
|
2023-01-26 07:48:12 +01:00
|
|
|
|
})];
|
|
|
|
|
}
|
2021-04-02 03:36:11 +02:00
|
|
|
|
}
|
2023-05-14 05:23:39 +02:00
|
|
|
|
}
|
2021-04-02 03:36:11 +02:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'unicodeEmoji': {
|
|
|
|
|
return [h(MkEmoji, {
|
|
|
|
|
key: Math.random(),
|
|
|
|
|
emoji: token.props.emoji,
|
2023-11-05 10:01:51 +01:00
|
|
|
|
menu: props.enableEmojiMenu,
|
|
|
|
|
menuReaction: props.enableEmojiMenuReaction,
|
2023-05-14 05:23:39 +02:00
|
|
|
|
})];
|
|
|
|
|
}
|
2018-03-31 14:41:08 +02:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'mathInline': {
|
|
|
|
|
return [h('code', token.props.formula)];
|
|
|
|
|
}
|
2019-01-25 15:08:06 +01:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'mathBlock': {
|
|
|
|
|
return [h('code', token.props.formula)];
|
|
|
|
|
}
|
2018-11-16 09:03:52 +01:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'search': {
|
|
|
|
|
return [h(MkGoogle, {
|
|
|
|
|
key: Math.random(),
|
|
|
|
|
q: token.props.query,
|
|
|
|
|
})];
|
|
|
|
|
}
|
2018-04-21 11:59:16 +02:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
case 'plain': {
|
2023-10-19 04:42:17 +02:00
|
|
|
|
return [h('span', genEl(token.children, scale, true))];
|
2023-05-14 05:23:39 +02:00
|
|
|
|
}
|
2022-07-12 05:03:38 +02:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
default: {
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
console.error('unrecognized ast type:', (token as any).type);
|
2018-09-11 20:32:47 +02:00
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
|
return [];
|
2018-03-31 14:41:08 +02:00
|
|
|
|
}
|
2023-05-14 05:23:39 +02:00
|
|
|
|
}
|
|
|
|
|
}).flat(Infinity) as (VNode | string)[];
|
2018-03-31 14:41:08 +02:00
|
|
|
|
|
2023-05-17 04:50:37 +02:00
|
|
|
|
return h('span', {
|
|
|
|
|
// https://codeday.me/jp/qa/20190424/690106.html
|
|
|
|
|
style: props.nowrap ? 'white-space: pre; word-wrap: normal; overflow: hidden; text-overflow: ellipsis;' : 'white-space: pre-wrap;',
|
2023-10-28 05:41:17 +02:00
|
|
|
|
}, genEl(rootAst, props.rootScale ?? 1));
|
2023-05-14 05:23:39 +02:00
|
|
|
|
}
|